﻿using System.Text;

namespace Chip8.Core
{
    internal sealed class Graphics
    {

        #region Public Properties

        public string DebugString
        {
            get
            {
                var sb = new StringBuilder();
                for (var x = 0; x < Constants.Width; x++)
                    for (var y = 0; y < Constants.Height; y++)
                    {
                        sb.Append(Buffer[x, y].ToString());
                        if (y == Constants.Height - 1)
                            sb.Append(Environment.NewLine);
                    }
                return sb.ToString();
            }
        }

        #endregion Public Properties

        #region Internal Properties

        internal Bit[,] Buffer { get; } = new Bit[Constants.Width, Constants.Height];

        #endregion Internal Properties

        #region Public Methods

        public void Clear()
        {
            for (var x = 0; x < Constants.Width; x++)
                for (var y = 0; y < Constants.Height; y++)
                    Buffer[x, y] = 0;
        }

        public Bit GetBufferValue(int x, int y) => Buffer[x, y];

        public void SetBufferValue(int x, int y, Bit value)
        {
            Buffer[x, y] = value;
        }

        #endregion Public Methods
    }
}